// pages/applylist/applylist.js
const app = getApp();
const API_URL = 'https://api.lailiaosheji.com/'
import api from '../../utils/api.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperArr:[],
    applyOptions:['报名中','即将开始报名'],
    currentIndex: 0,
    status: 1,
    examList: [],

    examTab: [
      { text: '报名列表', icon: '/images/apply.png', selectedIcon: '/images/apply_active.png' },
      { text: '我的报名', icon: '/images/myapply.png', selectedIcon: '/images/myapply_active.png' },
      { text: '个人中心', icon: '/images/profile.png', selectedIcon: '/images/profile_active.png' }
    ],
    currentTabbarIndex: 0

  },

  change(e) {
    this.setData({
      currentTabbarIndex: e.currentTarget.dataset.index
    })
    if (this.data.currentTabbarIndex == 0){
      wx.redirectTo({
        url: '/pages/applylist/applylist',
      })
    } else if (this.data.currentTabbarIndex == 1){
      wx.redirectTo({
        url: '/pages/myapply/myapply',
      })
    }else {
      wx.redirectTo({
        url: '/pages/profile/profile',
      })
    }
    
  },

  handleChangeOption(e){
    this.setData({
      currentIndex: e.currentTarget.dataset.index,
      status: e.currentTarget.dataset.status
    })
    this.getExamList()
  },

  //请求考试列表
  getExamList() {
    wx.showLoading({
      title: '加载中',
    })
    let obj = {}
    obj.status = this.data.status
    api.POST('applet/exam/finds', obj, res => {
      console.log(res)
      this.setData({
        examList: res.data.data
      })
      wx.hideLoading()
    })
  },

  // 报名详情页
  goToDetail(e){
    app.globalData.examItem = e.currentTarget.dataset.item
    // console.log(app.globalData)
    wx.navigateTo({
      url: '/pages/detail/detail'
    })
  },

  // 请求轮播图片
  getSwiper(){
    api.POST('/applet/RotationChart/finds',{},res => {
      console.log(res)
      this.setData({
        swiperArr: res.data.data
      })
    })
  },

  //预览轮播图
  previewImage(e) {
    wx.previewImage({
      urls: [API_URL + e.currentTarget.dataset.rotation_chart_url]
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSwiper()
    this.getExamList()

    this.setData({
      isExam: true
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})